from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email.header import Header
from email import encoders
import smtplib


def main_qq(server, Maintext, image_path1, image_path2, qq_username, qq_password):
    con = smtplib.SMTP_SSL('smtp.qq.com', 465)

    # 登录邮箱
    con.login(f'{qq_username}', f'{qq_password}')

    msg = MIMEMultipart()

    subject = Header(f'{server}', 'utf-8').encode()
    msg['Subject'] = subject

    msg['From'] = f'{qq_username} <{qq_username}>'
    msg['To'] = f'{qq_username}'

    # 添加邮件正文
    text = MIMEText(Maintext, 'plain', 'utf-8')
    msg.attach(text)

    # 第一个图片附件
    with open(image_path1, 'rb') as f:
        mime1 = MIMEBase('image', 'jpg', filename="a.png")
        mime1.add_header('Content-Disposition', 'attachment', filename="a.png")
        mime1.add_header('X-Attachment-Id', '0')
        mime1.add_header('Content-ID', '<0>')
        mime1.set_payload(f.read())
        encoders.encode_base64(mime1)
        msg.attach(mime1)

    # 第二个图片附件
    with open(image_path2, 'rb') as f:
        mime2 = MIMEBase('image', 'jpg', filename="b.png")
        mime2.add_header('Content-Disposition', 'attachment', filename="b.png")
        mime2.add_header('X-Attachment-Id', '1')
        mime2.add_header('Content-ID', '<1>')
        mime2.set_payload(f.read())
        encoders.encode_base64(mime2)
        msg.attach(mime2)

    # 发送邮件
    con.sendmail(f'{qq_username}', f'{qq_username}', msg.as_string())
    con.quit()


